<template>
  <div class="search-box-wrap">
    <el-input
      v-model="newSearchValue"
      class="search-input"
      type="text"
      :placeholder="$attrs['placeholder-text']"
      @input="updateView($event)"
      @keyup.enter.native="queryData"
    >
      <!-- :style="'width:' + width" -->
      <i slot="prefix" class="iconfont iconicon_magnifying fs14"></i>
      <el-button slot="append" @click.native="queryData">搜索</el-button>
    </el-input>
  </div>
</template>

<script>

export default {
  name: 'SearchBox',
  inheritAttrs: false,
  props: {
    width: {
      type: String,
      default: '275px'
    },
    searchValue: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      newSearchValue: this.searchValue
    }
  },
  watch: {
    newSearchValue(newVal, oldVal) {
      this.$emit(`update:searchValue`, newVal)
    }
  },
  created() {
  },
  methods: {
    updateView(e) {
      this.$forceUpdate()
    },
    queryData() {
      this.$emit('queryData')
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "~@/assets/styles/variables";

  .search-box-wrap {
    .search-input {
      width: 280px;
      height: 36px;
      ::v-deep .el-input__inner {
        padding: 0 12px 0 38px !important;
        border-top-left-radius: 50px;
        border-bottom-left-radius: 50px;
        height: 36px;
        line-height: 36px;
        border-right: 0 !important;
      }
      ::v-deep .el-input-group__append {
        border-top-right-radius: 50px;
        border-bottom-right-radius: 50px;
      }
      ::v-deep .el-input-group__append {
        width: 72px;
        background-color: $operateBtnBack;
        color: $white;
        border: 0;
        padding: 0;
        font-size: 13px;
        text-align: center;
      }
      ::v-deep .el-input-group__append button.el-button {
        width: 100%;
        height: 36px !important;
        padding: 0;
        margin: 0;
      }
      @media (max-width: 1360px) {
        ::v-deep .el-input-group__append button.el-button {
          height: 32px !important;
        }
      }
    }
  }
  @media (max-width: 1360px) {
    .search-box-wrap {
      .search-input {
        width: 280px !important;
        height: 32px !important;
        ::v-deep .el-input__inner {
          height: 32px !important;
          font-size: 12px !important;
          line-height: 32px !important;
        }
        ::v-deep .el-input-group__append {
          width: 64px;
          font-size: 12px;
      }
      }
    }
  }
</style>
